package ${packageName}.listener;

import ${packageName}.domain.${entityName};
import com.mybatisflex.annotation.InsertListener;
import com.mybatisflex.annotation.UpdateListener;
import java.time.LocalDateTime;

/**
 * ${modelName}自动填充
 * @Author: 不是菜鸡爱编程
 * @Date:
 * @Description：
 */
public class ${listenerName} implements InsertListener, UpdateListener {
    /**
     * 在插入数据时调用
     *
     * @param o o
     */
    @Override
    public void onInsert(Object o) {
        ${entityName} ${entityName?uncap_first} = (${entityName}) o;<#list columns as column><#if column??><#if column.type="DATETIME" && column.propertyName="CreateTime">
        ${entityName?uncap_first}.setCreateTime(LocalDateTime.now());<#elseif column.type="DATETIME" && column.propertyName="UpdateTime">
        ${entityName?uncap_first}.setUpdateTime(LocalDateTime.now());</#if></#if></#list>
    }

    /**
     * 在更新数据时调用
     *
     * @param o o
     */
    @Override
    public void onUpdate(Object o) {
        ${entityName} ${entityName?uncap_first} = (${entityName}) o;<#list columns as column><#if column??><#if column.type="DATETIME" && column.propertyName="UpdateTime">
        ${entityName?uncap_first}.setUpdateTime(LocalDateTime.now());</#if></#if></#list>
    }
}